package com.neu.servlet.snn;

import com.neu.util.ExcelUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

@WebServlet(name = "DaoChuServlet", urlPatterns = {"/DaoChuServlet.do"})
public class DaoChuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session =request.getSession();
        List<Map<String,Object>> list = (List<Map<String, Object>>) session.getAttribute("orderList");
        OutputStream out = response.getOutputStream();
        String [] culName={"g_name","nums","prices"};
        String [] labelName={"商品名称","件数","销售金额"};
        response.setHeader("content-disposition","attachment;filename=xiaoliang.xlsx");
        ExcelUtil.writeExcel(out,list,culName,labelName);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
